import Oidc from 'oidc-client';
// import Store from '@/extend/store';

const locals_href = window.location.origin;

const config = {
  authority: WEB_CONFIG.VUE_APP_ODIC_HOST,
  client_id: 'Taekwondo_App',
  redirect_uri: process.env.VUE_APP_DIREVTOR === 'login' ? WEB_CONFIG.VUE_APP_ODIC_CALLBACK : (locals_href + '/callback.html'),
  response_type: 'code',
  scope: 'openid Taekwondo',
  silentRequestTimeout: 10000,
  revokeAccessTokenOnSignout: true, // 退出销毁终结点token
  automaticSilentRenew: true, // 指示是否应在访问令牌过期之前自动尝试续订该令牌的标志。尝试是由于引发accessTokenExpiring事件而进行的。
  post_logout_redirect_uri: locals_href + '/index.html',
  loadUserInfo: false,
  monitorSession: false
};
let mgr = global.mgr;
if (!global.mgr) {
  console.log('build mgr');
  mgr = new Oidc.UserManager(config);
  global.mgr = mgr;
}
mgr.events.addUserSignedOut(function () {
  console.log('User signed out of OP');
  // mgr.removeUser();
});

export default mgr;
